package 反射.作业;

import cn.itcast.domain.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class 通过反射操作构造方法 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {

        Class clazz = Class.forName("cn.itcast.domain.Student");

        Constructor constructor = clazz.getDeclaredConstructor();

        constructor.setAccessible(true);

        Object o = constructor.newInstance();

        System.out.println(o);

        Class clazz2 = Class.forName("cn.itcast.domain.Student");

        Constructor constructor1 = clazz2.getDeclaredConstructor(String.class, Integer.class);

        constructor1.setAccessible(true);

        Object o1 = constructor1.newInstance("这是修改的名字", 20);

        System.out.println(o1);
    }
}
